#!/bin/bash

choices="lock\nlogout\nshutdown\nreboot"

chosen=$(echo -e "$choices" | dmenu -i -p "Operation:")

# 退出桌面
chosen_logout(){
    if [[ "$DESKTOP_SESSION" == "Openbox" ]]; then
        openbox --exit
    elif [[ "$DESKTOP_SESSION" == "bspwm" ]]; then
        bspc quit
    elif [[ "$DESKTOP_SESSION" == "i3" ]]; then
        i3-msg exit
    elif [[ "$DESKTOP_SESSION" == "dwm" || "$DESKTOP_SESSION" == "DWM" ]]; then
        # 需要dwm 打fsignal补丁
        # xsetroot -name "fsignal:<signum>"
        xsetroot -name "fsignal:1"
    else
        notifystr="不知道该窗口退出命令。"
        notify-send $notifystr;
    fi
}

# 锁屏
chesen_lock(){
    if [[ -f /usr/bin/i3lock ]]; then
        if [[ -f ~/.dwm/scripts/app-starter.sh ]];then
            /bin/bash ~/.dwm/scripts/app-starter.sh blurlock
        elif [[ -f ~/.dwm/scripts/i3lock-get-screen-image-fancy.sh ]];then
           ~/.dwm/scripts/i3lock-get-screen-image-fancy.sh
        else
            i3lock
        fi
    elif [[ -f /usr/bin/slock ]]; then
        # /bin/bash ~/.config/i3/scripts/xslock.sh
        /bin/bash ~/.dwm/scripts/scripts/xslock.sh
    else
        notifystr="没有找到相关锁屏软件（i3lock、slock）位置。"
        notify-send $notifystr;
    fi
}


case "$chosen" in
    lock) chesen_lock;;
    logout) chosen_logout;;
    reboot) systemctl reboot;;
    shutdown) systemctl poweroff;;
esac

